/**
 * @param {number} num 设置每页多少条数据
 * @param {boolean} flag  设置每页是否带表头，true带表头，false不带
 */
function setPage(num, flag) {
    let pageDataNum = 50; //一共多少数据
    let pageNum;  //一共多少页
    let numa = 1; //用于遍历的数
    pageNum = Math.ceil(pageDataNum / num);  //得到多少页
    for (let i = 0; i < pageNum; i++) {
        //创建最外层div
        let divLayui = document.createElement("div");
        divLayui.setAttribute("class", "layui-container-fluid")
        //设置整个页面的高度，使打印在一个页面上
        divLayui.style.height = "1450px"
        //创建boxdiv(是divLayui的子元素)
        let box = document.createElement("div");
        box.setAttribute("class", "box")
        /*  let divRpt = document.createElement("div");
            divRpt.setAttribute("id", "rpt_header");
            divRpt.innerHTML = document.getElementById("rpt_header").innerHTML
            box.appendChild(divRpt) */
        box.innerHTML = `<div id="rpt_header">
        <div class="layui-row" style="text-align: right">
            <h3 class="fontweight">表五</h3>
        </div>
        <div class="layui-row" style="text-align: center">
            <h1>2020年度职工购房补贴发放一览表</h1>
        </div><br>
        <div class="content">
            <div class="box1">
                <h3 class="fontweight">单位(公章): </h3>
                <h3>***</h3>
            </div>
            <div class="box3">
                <h3 class="fontweight">　报表人:</h3>
                <h3>***</h3>
            </div>
            <div class="box2">
                <h3 class="fontweight">法定代表人:</h3>
                <h3>***</h3>
            </div>
        </div>
        <div class="content">
            <div class="box1">
                <h3 class="fontweight"> 单位编码:</h3>
                <h3>2100000000*******</h3>
            </div>
            <div class="box3">
                <h3 class="fontweight">制表时间:</h3>
                <h3>2021-09-15</h3>
            </div>
            <div class="box2">
                <h3 class="fontweight">房改负责人:</h3>
                <h3>***</h3>
            </div>
        </div>
        <div class="content">
            <div class="box1">
                <h3 class="fontweight"> 联系电话: </h3>
                <h3>13614900222</h3>
            </div>
            <div class="box4">
                <h3 style="float: right;">单位(补贴额：元，面积：平方米)     (共<span id="rpt_npage">${pageNum}</span>页 第<span id="rpt_tpage">${i + 1}</span>页) </h3>
            </div>
        </div>`
        divLayui.appendChild(box)
        //创建table（是box的子元素)
        let table = document.createElement("table");
        table.setAttribute("class", "tg");
        table.setAttribute("style", "undefined;table-layout: fixed; width: 1800px")
        //创建colgroup（是table的子元素)
        let colgroup = document.createElement("colgroup");
        colgroup.innerHTML = document.getElementsByTagName("colgroup")[0].innerHTML
        table.appendChild(colgroup)
        if (flag == true) {
            console.log("是否带有表头")
            let thead = document.createElement("thead");
            thead.innerHTML = document.getElementsByTagName("thead")[0].innerHTML
            table.appendChild(thead)
        }
        //创建tbody（是table的子元素)
        let tbody = document.createElement("tbody");
        for (let j = 0; j < num; j++) {
            let tr = document.createElement("tr")
            if (numa < pageDataNum * 2)
                tr.innerHTML = document.getElementsByTagName("tbody")[0].childNodes[numa].innerHTML;
            numa = numa + 2;
            tbody.appendChild(tr);
        }
        table.appendChild(tbody)
        box.appendChild(table)
        //创建divFooter(是table的子元素)
        let divFooter = document.createElement("div")
        divFooter.setAttribute("id", "rpt_footer")
        divFooter.innerHTML = `footer测试 `
        box.appendChild(divFooter)
        document.getElementsByTagName("body")[0].appendChild(divLayui)

    }
    console.log(document.getElementsByClassName("layui-container-fluid")[0].style.display = "none")
}
//调用方法
setPage(10, true)
